home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: readDiskMessage.c,v $
- * $Revision: 1.2 $
- * $Date: 1996/05/04 23:51:47 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "queue_consist.h"
- #include "sysdefs.h"
- #include <sys/stat.h>
- #include "ess.h"
- #include "checking.h"
- #include "list.h"
- #include "error.h"
- #include "tid.h"
- #include "pool.h"
- #include "io.h"
- #include "bitvec.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "disk.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "bf.h"
- #include "link.h"
- #include "volume.h"
- #include "trace.h"
- #include "msgvector.h"
-
- #include "disk_funcs.h"
- #include "queues.h"
- #include "diskproc_globals.h"
- #include "diskproc_intfuncs.h"
- #include "diskproc_extfuncs.h"
- #include "softwareVersion.h"
-
- #ifdef linux
- #include <bsd/signal.h>
- #endif linux
-
-
- /*ARGSUSED*/
- static void
- riseAndShine(
- )
- {
- /*
- * See if parent(server) is still around
- * after having blocked on the semphore.
- */
- int pid;
-
-
- TRPRINT(TR_DISKRW, TR_LEVEL_2,
- ("Alarm woke up disk process"));
- #ifdef hpux
- if((pid = getpgrp2(Parent))<0) {
- #elif defined(linux)
- if((pid = getpgrp())<0) {
- #else
- if((pid = getpgrp(Parent))<0) {
- #endif
- if(errno == ESRCH) { /* no such process */
- pid = 1; /* as if inherited by init */
- } else {
- SM_ERROR(TYPE_FATAL, errno);
- }
- }
- if(pid == 1) {
- /*
- * Parent is gone. We were inherited by init().
- * Server died so we'd better shut ourselves down.
- * No need for a core file.
- */
- SM_ERROR(TYPE_STOP, esmSERVPROCDIED);
- }
- errno = EINTR; /* to be sure */
-
- }
-
-
- static int
- rawDeviceSetup()
- {
- struct stat statInfo;
-
- /*
- * See if the named file is a raw disk
- */
- if (stat(DiskName, &statInfo) < 0) {
- SM_ERROR(TYPE_SYS, errno);
- return esmFAILURE; /* not ok */
- }
- /* if it's not a character device, its not a raw disk */
- if ((statInfo.st_mode & S_IFMT) != S_IFCHR) {
- RawDev = FALSE;
- BlockBuf = NULL;
- } else {
- RawDev = TRUE;
- BlockBufSize = MAX_IO_LIST * MIN_PAGESIZE;
- BlockBuf = (char*) malloc(BlockBufSize + MIN_PAGESIZE/*align*/);
- if (BlockBuf == NULL) {
- SM_ERROR(TYPE_SYS, esmMALLOCFAILED);
- return (esmFAILURE);
- }
- /* align the buffer */
- BlockBuf = (char*)
- ( ((int) (BlockBuf+MIN_PAGESIZE)) & ~(MIN_PAGESIZE - 1));
-
- }
- return(esmNOERROR);
- }
-
-
- void
- readDiskMessage ()
-
- {
- DISKMSG *message;
-
- struct sigvec sv;
- ShmOffset shmoffset;
-
- /* signal(SIGALRM, riseAndShine); */
- sv.sv_mask = 0;
- sv.sv_flags = 0;
- #if defined(SIG_PFV) || defined(hpux) || defined(linux)
- /* Sun C++ and hpux define SIG_PFV in sys/signal.h */
- sv.sv_handler = (void (*)(...))riseAndShine;
- #else
- sv.sv_handler = riseAndShine;
- #endif
-
- #ifdef hpux
- sigvector(SIGALRM, &sv, NULL);
- #else
- sigvec(SIGALRM, &sv, NULL);
- #endif hpux
-
-
- for (;;) {
-
-
- #if MAGIC_CHECKING IS_ENABLED
- if(DiskQueue->toDisk.magic != QMAGIC) {
- SM_ERROR(TYPE_FATAL, esmBADMESSAGEMAGIC);
- }
- #endif MAGIC_CHECKING IS_ENABLED
- getMutex(&(DiskQueue->toDisk.mutex));
- if(toDiskEmpty(DiskQueue)) {
- struct sembuf _sembuf;
-
- DiskQueue->toDisk.mutex.willBlock=TRUE;
- giveMutex(&(DiskQueue->toDisk.mutex));
- /*
- * We'll block. Set a timer so we don't hang around forever
- * should the server die (grot).
- */
- TRPRINT(TR_DISKRW, 0, ("toDisk empty; blocking"));
- alarm(60/*seconds*/ * 1 );
-
- /*
- * wait on the semaphore for this disk
- */
-
- _sembuf.sem_num = SemNum;
- _sembuf.sem_op = -1; /* a semaphore P operation */
- _sembuf.sem_flg = 0;
-
- TRPRINT(TR_DISKRW, TR_LEVEL_1,
- ("P on SYSV semaphore #%d, SemId 0x%x",
- SemNum,SemId));
-
- {
- int e;
- e = semop(SemId, &_sembuf, 1);
- TRPRINT(TR_DISKRW, TR_LEVEL_1,
- ("wakes up with errno %d%s", errno, errno==EINTR?"(EINTR)":""));
- if( (e < 0 ) && (errno != EINTR)) {
- SM_ERROR(TYPE_FATAL, errno);
- }
- }
- alarm(0);
- getMutex(&(DiskQueue->toDisk.mutex));
- DiskQueue->toDisk.mutex.willBlock=FALSE;
- giveMutex(&(DiskQueue->toDisk.mutex));
- continue; /* loop */
- } else {
-
- /*
- * il y a quelque chose dans la queue
- */
- TRPRINT(TR_DISKRW, TR_LEVEL_1, ("dequeueing from toDisk"));
- deq_to(DiskQueue, shmoffset);
- message = ShmOffsetToAddress(shmoffset, DISKMSG);
-
- }
- giveMutex(&(DiskQueue->toDisk.mutex));
-
- /*
- * don't let the alarm go off during disk i/o
- */
-
- TRPRINT(TR_DISKRW, TR_LEVEL_1, ("Got message type %d to disk %d",
- message->header.type, SemNum));
-
-
- /*
- * check the message to see if the magic is correct
- */
- if (message->diskmagic != DISK_MESSAGE_MAGIC) {
-
- /*
- * reply with an error
- */
- fprintf(stderr,
- "Possible version mismatch between server and diskrw (%x)\n",
- SOFTWARE_VERSION);
- SM_ERROR(TYPE_WARNING, esmBADMESSAGEMAGIC);
- message->header.params.out.errno = esmBADMESSAGEMAGIC;
- message->diskmagic = DISK_MESSAGE_MAGIC;
- replyDiskMessage( message );
- }
-
- /*
- * switch on message type
- */
- switch (message->header.type) {
-
- case OPEN_DISK:
-
- openLocalDisk(message, DiskName); /* Dies if unsuccessful */
- if (rawDeviceSetup() != esmNOERROR) {
- SM_ERROR(TYPE_STOP, errno);
- }
- break;
-
- case CLOSE_DISK:
-
- closeLocalDisk(message);
- break;
-
- case READ_BLOCK:
-
- readLocalDisk(message);
- break;
-
- case WRITE_BLOCK:
-
- writeLocalDisk(message);
- break;
-
- case DUMP_MON:
-
- dumpLocalProfiling(message);
- break;
-
- case FSYNC_DISK:
-
- fsyncLocalDisk(message);
- break;
-
- default:
- fprintf(stderr, "unknown header type %d\n",
- message->header.type);
-
- SM_ERROR(TYPE_FATAL, esmINTERNAL);
- break;
- }
- }
- }
-